package com.lyf.boot.modules.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lyf.boot.annotation.Log;
import com.lyf.boot.core.model.IdArrDto;
import com.lyf.boot.core.model.PageInfo;
import com.lyf.boot.core.model.R;
import com.lyf.boot.enums.BusinessType;
import com.lyf.boot.modules.system.entity.dto.SysOperLogPageDto;
import com.lyf.boot.modules.system.entity.vo.SysOperLogVo;
import com.lyf.boot.modules.system.service.ISysOperLogService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作日志
 * @author Luyufan
 * @date 2023/8/24 15:31
 */
@RestController
@RequestMapping("/sysOperLog")
@RequiredArgsConstructor
public class SysOperLogController {

    private final ISysOperLogService sysOperLogService;

    /**
     * 分页查询系统日志
     * @param dto 请求参数
     * @return 分页数据
     */
    @SaCheckPermission("sys:operLog:list")
    @PostMapping("/getSysOperLogPage")
    public R<PageInfo<SysOperLogVo>> getSysOperLogPage(@RequestBody SysOperLogPageDto dto){
        return R.ok(sysOperLogService.getSysOperLogPage(dto));
    }

    /**
     * 删除操作日志
     * @param dto 请求参数
     * @return 删除结果
     */
    @SaCheckPermission("sys:operLog:delete")
    @PostMapping("/deleteSysOperLog")
    @Log(module = "操作日志", business = "删除日志", businessType = BusinessType.DELETE)
    public R<Void> deleteSysOperLog(@RequestBody @Valid IdArrDto dto){
        sysOperLogService.deleteSysOperLog(dto.getIds());
        return R.ok();
    }

    /**
     * 清除操作日志
     * @return 清楚结果
     */
    @SaCheckPermission("sys:operLog:clear")
    @PostMapping("/clearSysOperLog")
    @Log(module = "操作日志", business = "清除日志", businessType = BusinessType.CLEAR)
    public R<Void> clearSysOperLog(){
        sysOperLogService.clearSysOperLog();
        return R.ok();
    }
}
